package com.xiexin.web.controller;

import com.xiexin.web.config.ResponseUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 下载 Excel模板
 */
@RestController
@RequestMapping("/getExcel")
public class ExcelController {
    @RequestMapping("/getFile")
    public ResponseEntity<byte[]> getFile(){
        String path = "";
        File file =null;
        try {
          path  = ResourceUtils.getURL("classpath:").getPath()+"static";

            System.out.println("path = " + path);
            String path1=path+"/ordersetting_template.xlsx";
          file = ResourceUtils.getFile(path1);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        try {
            return  ResponseUtils.buildResponseEntity(file) ;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  null;
    }
}
